#include <stdio.h>
#include <stdlib.h>

typedef struct note {
	int data;
	struct note * next;
}Elem;

Elem *CreateCyclicLink(int a[],int n){
	Elem *p,*h=NULL,*t;
	int i;
	for (i=0;i<n;i++){
		p= (Elem *) malloc (sizeof (Elem));
		p->data=a[i];
		if (!h){
			p->next=p;
			h=t=p;
		}
		else {
			p->next=h;
			t=t->next=p;
		}
	}
	return h;
} 

void PrintLink(Elem *head){
	Elem *p;
	for (p=head;p;p=p->next)
		printf("%-8d",p->data);	
}

Elem *JoseRing(Elem *h){
	Elem *p=h,*t,*pn=NULL,*tn;
	int i,s=3;
	for(t=h;t->next!=p;t=t->next);
	while (p- p->next){
		for (i=0;i<s-1;i++){
			t=p;
			p=p->next;
		} 
		t->next=p->next;
		p->next=NULL;
		if(!pn)  tn=pn=p;
		else{
			tn->next=p;
			tn=tn->next;
		}	
		p=t->next;
	}
	if (!pn)	pn=p;
	else	tn->next=p;
	p->next=NULL;
	return pn;
}

int main(void){
	Elem *head,*h;
	int a[10]={1,2,3,4,5,6,7,8,9,10};
	head=CreateCyclicLink(a,10);
	h=JoseRing(head);
	PrintLink(h);
	return 0;
}
